/**
 * @param {number[]} nums
 * @return {number[][]}
 */
 var subsetsWithDup = function(nums) {
     nums.sort((a,b)=>a-b)
    let res =[],curr=[],length=nums.length
    function tools(stackIndex){
        res.push([...curr])
        for(let i=stackIndex;i<length;i++){
            if(i>stackIndex&&nums[i]==nums[i-1]) continue
            curr.push(nums[i])
            tools(i+1)
            curr.pop()
        }
    }
    tools(0)
    return res
};
console.log(subsetsWithDup([4,4,4,1,4]));
